﻿@{
    ViewBag.Title = "寄售库存出库输入";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script>
    var checkData = false;
    var currRowId = 0;
    var status = '@ViewBag.status';
    $(function () {
        initControl();
        gridList();
    });

    function initControl() {
        var currFDocuNO = $.request("currFDocuNO");
        var FAccountDate = $.request("FAccountDate");
        if (currFDocuNO != '') {
            $.ajaxSetup({ async: false });
            $.get("/WareHouse/Consignment/GetConsignmentOutItemByDocuNOJson", { FDocuNO: currFDocuNO, FAccountDate: FAccountDate }, function (data, status) {
                if (status == "success") {
                    data = eval("(" + data + ")");
                    setDataByJson('#form1', data);
                    if ($('#FDocuNO').val() != '') {
                        $('#FDocuNOShow').val($('#FDocuNO').val());
                    }
                    lockInputById("#form1");
                } else {
                    alert("出错了！");
                }
            });
            $.ajaxSetup({ async: true });
        }
        initBindSelect('#form1');
        if (status == 'I') {
            $('#pageTitle').text("输入");
            $('#btn_add').show();
        } else {
            $('#pageTitle').text("单据");
            $('#btn_add').hide();
        }
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url:"/WareHouse/Consignment/GetConsignmentOutListByDocuNOJson",
            postData: { FDocuNO: $('#FDocuNO').val(), FAccountDate: $.request("FAccountDate") },
            height: $(window).height() - 220,
            colModel:[
                    @if (@ViewBag.status == "I") { 
                    <text>
                    {
                        label: '操作', name: '', width: 60, align: 'center', sortable: false, frozen: true, formatter: function (cellvalue, options, rowObject) {
                            return '<a id="" class="btn btn-primary center-block btn-1" onclick="do_delete_item(\'' + rowObject.FDocuListID + '\')" style="width:45px;">删除 </a>';
                        }
                    },
                    </text>
                    }
                    { label: '零件编号', name: 'FProductionNO', width: 130, align: 'left', sortable: false, frozen: true },
                    { label: '零件名称', name: 'FProductionName', width: 200, align: 'left', sortable: false, frozen: true },
                    { label: '开票数量', name: 'FQuantity_KP', width: 80, align: 'right', sortable: false },
                    { label: '实际数量', name: 'FQuantity', width: 80, align: 'right', sortable: false },
                    { label: '零件单价(元)', name: 'FPrice', width: 100, align: 'right', sortable: false },
                    { label: '金额(元)', name: 'FAmount', width: 80, align: 'right', sortable: false },
                    { label: '备注说明', name: 'FDescription', width: 240, align: 'left', sortable: false },
                    { label: '供货单位名称', name: 'FProCompanyName', width: 130, align: 'left', sortable: false },
                    { label: '零件分类', name: 'FProductionTypeName', width: 80, align: 'left', sortable: false },
                    { label: '仓库编号', name: 'FStoreNO', width: 80, align: 'left', sortable: false },
                    { label: '仓库名称', name: 'FStoreName', width: 130, align: 'left', sortable: false },
                    { label: '供货单位', name: 'FProCompanyNO', width: 70, align: 'left', sortable: false, hidden: true },
                    { label: 'ID(隐藏)', name: 'FDocuListID', width: 20, align: 'center', sortable: false, hidden: true },
                    { label: '零件分类编码(隐藏)', name: 'FProductionTypeNO', width: 20, align: 'center', sortable: false, hidden: true },
            ],
            viewrecords: true,  //是否显示行数
            rownumWidth: 40,
            gridComplete: function () {

            },
            loadComplete: function () {
                var rowDatas = $gridList.jqGrid("getRowData");
                var length = rowDatas.length + 1;
                if (length > 0) {
                    if (currRowId == 0) {
                        currRowId = 1;
                    } else if (currRowId > length) {
                        currRowId = length;
                    }
                }
                //if (currRowId > 0) {
                //    $gridList1.jqGrid('setSelection', currRowId);
                //    var $grid = $('#gview_gridList1 .ui-jqgrid-bdiv');
                //    if (isJump) {
                //        $grid.setScrollTop(length, currRowId);
                //        isJump = false;
                //    } else {
                //        var top = $grid.scrollTop();
                //        $grid.scrollTop(top + 1);
                //    }
                //}
            },
            onSelectRow: function (rowid) {
                //currRowId = rowid;
            },
            onPaging: function (page_btn) {
                //currRowId = 0;
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $gridList.jqGrid('setFrozenColumns');
    }
    function btn_add() {
        $.detailOpenTop({
            id: "OrderForm",
            title: '请输入寄售出库单据信息:',
            url: "/WareHouse/Consignment/ConsignmentOutOrder?FDocuNO=" + $("#FDocuNO").val() + "&FDocuNOShow=" + $('#FDocuNOShow').val() + "&FHappenComNO=" + $('#FHappenComNO').val() + "&FCurDate=" + $('#FCurDate').val() + "&FDocuTypeNO=" + $('#FDocuTypeNO').val() + "&FDescription=" + $('#FDescription').val() + "&FCredence=" + escape($('#FCredence').val()),
            width: 900,
            height: 600,
        });  
    }
    function do_delete_item(id) {
        $.modalConfirm("注：您确定要【删除】当前行的数据吗？", function (r) {
            if (r) {
                $.submitForm({
                    url: "/WareHouse/Consignment/SubmitConsignmentOutForm?status=D",
                    param: { keyValue: id },
                    success: function () {
                        var currFDocuNO = $("#FDocuNO").val();
                        var reloadPage = false;
                        if (currFDocuNO != '') {
                            $.ajaxSetup({ async: false });
                            $.get("/WareHouse/Consignment/GetConsignmentOutItemByDocuNOJson", { FDocuNO: currFDocuNO }, function (data, status) {
                                if (status == "success") {
                                    if (data == '') {
                                        reloadPage = true;
                                    }
                                } else {
                                    alert("出错了！");
                                }
                            });
                            $.ajaxSetup({ async: true });
                        }
                        if (reloadPage) {
                            window.location.href = "/WareHouse/Consignment/ConsignmentOutInput?status=I";
                        }
                        reloadGrid();
                    }
                })
            }
        });
    }
    function reloadPageData(data){
        setDataByJson('#form1',data);
        initBindSelect("#form1");
        lockInputById("#form1");
        reloadGrid();
    }
    function reloadGrid() {
        $("#gridList").jqGrid('setGridParam', {
            postData: { FDocuNO: $('#FDocuNO').val() },
        }).trigger('reloadGrid');
    }
    function btn_return() {
        parent.reloadGrid1();
        parent.$.detailClose();
    }
</script>

<div class="ui-layout" id="layout" style="height:100%; width:100%;">
    <form id="form1">
        <table class="form" style="width: 98%; margin: 0 auto; border-bottom: 2px solid #ccc;">
            <tr>
                <td style="width: 240px; text-align: left; text-indent:40px;">
                    <h2 id="pageTitle" style="font-family:隶书;font-weight:bold;font-size:26px"></h2>
                </td>
                <td style="text-align:center;">
                    <h2 style="font-family:隶书;font-weight:bold;font-size:26px">寄售出库单</h2>
                </td>
                <td style="width: 240px; text-align: center;">
                    <div class="btn-group" style="margin-top:9px;">
                        <a id="btn_add" class="btn btn-primary center-block " onclick="btn_add()"><span class="glyphicon glyphicon-ok"></span> 新增</a>
                    </div>
                    <div class="btn-group" style="margin-top:9px;margin-left:20px;">
                        <a id="btn_return" class="btn btn-primary center-block" onclick="btn_return()"><span class="glyphicon glyphicon-remove"></span> 返回</a>
                    </div>
                </td>
            </tr>
        </table>
        <table class="form" style="width: 98%; margin: 0 auto;">
            <tr>
                <th class="formTitle" style="width:60px;">&nbsp;</th>
                <td class="formValue input-width-140" style="width:150px;">
                    &nbsp;
                </td>
                <th class="formTitle" style="width:60px;">&nbsp;</th>
                <td class="formValue input-width-185" style="width:200px;">
                    &nbsp;
                </td>
                <td class="">
                    &nbsp;
                </td>
                <th class="formTitle" style="width:60px;">单据编号</th>
                <td class="formValue input-width-120" style="width:140px;">
                    <input id="FDocuNOShow" name="FDocuNOShow" type="text" class="form-control" disabled="disabled" value="@ViewBag.fdocunoTemp" />
                    <input id="FDocuNO" name="FDocuNO" type="hidden" value="">
                </td>
            </tr>
            <tr>
                <th class="formTitle">领料单位</th>
                <td class="formValue input-width-140">
                    <select id="FHappenComNO" name="FHappenComNO" class="form-control">
                        <option value="">&nbsp;</option>
                        @foreach (var item in ViewBag.fhappencomList)
                        {
                            <option value="@item.UnitNO">@item.UnitNO @item.UnitShortName</option>
                        }
                    </select>
                </td>
                <th class="formTitle">&nbsp;</th>
                <td class="formValue input-width-185">
                    &nbsp;
                </td>
                <td class="">
                    &nbsp;
                </td>
                <th class="formTitle">单据日期</th>
                <td class="formValue input-width-120">
                    <input id="FCurDate" name="FCurDate" type="text" class="form-control input-wdatepicker" value="@DateTime.Now.ToString("yyyy-MM-dd")" onfocus="WdatePicker()" />
                </td>
            </tr>
            <tr>
                <th class="formTitle">发生方式</th>
                <td class="formValue input-width-140">
                    <select id="FDocuTypeNO" name="FDocuTypeNO" class="form-control">
                        @foreach (var item in ViewBag.fdocutypenoList)
                    {
                            <option value="@item.FTypeNO">@item.FTypeNO @item.FTypeName</option>
                    }
                    </select>
                </td>
                <th class="formTitle">摘要说明</th>
                <td class="formValue input-width-185">
                    <input id="FDescription" name="FDescription" type="text" class="form-control " value="" />
                </td>
                <td class="">
                    &nbsp;
                </td>
                <th class="formTitle">凭证编号</th>
                <td class="formValue input-width-120">
                    <input id="FCredence" name="FCredence" type="text" class="form-control " />
                </td>
            </tr>
        </table>
        <div style="width:98%;margin:0 auto;border:1px solid #ccc;margin-top:5px;margin-bottom:5px;">
            <table id="gridList"></table>
        </div>
        <table class="form" style="width: 98%; margin: 0 auto;">
            <tr>
                <td>&nbsp;</td>
                <th class="formTitle" style="width:100px;">输入人员</th>
                <td class="formValue bill-input" style="width:140px;">
                    <input id="FCreateBy" name="FCreateBy" type="text" class="form-control" readonly="readonly" value="@FriendStar.Code.OperatorProvider.Provider.GetCurrent().UserCode" />
                </td>
                <th class="formTitle" style="width:80px;">输入日期</th>
                <td class="formValue bill-input" style="width:180px;">
                    <input id="FCreateDate" name="FCreateDate" type="text" class="form-control" readonly="readonly" value="@DateTime.Now.ToString("yyyy-MM-dd")" />
                </td>
                <th class="formTitle" style="width:80px;">审核人员</th>
                <td class="formValue bill-input" style="width:140px;">
                    <input id="FAuditingBy" name="FAuditingBy" type="text" class="form-control" readonly="readonly" value="" />
                </td>
                <th class="formTitle" style="width:80px;">审核日期</th>
                <td class="formValue bill-input" style="width: 180px;">
                    <input id="FAuditingDate" name="FAuditingDate" type="text" class="form-control" readonly="readonly" />
                </td>
            </tr>
        </table>
    </form>
</div>






